<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if(!class_exists('CI_Model')) { class CI_Model extends Model {} }

class Articles_model extends CI_Model {
	var $perpage = 10;
	var $url;
	public function __construct() {
	   parent::__construct();
	   $this->url = $this->uri->segment(1);
	}
	public function index() {
		$parent = $this->db->select()->from('content')->where('page_model', 'articles')->where('page_function', 'index')->get()->row_array();
		$data['pages'] = $this->content_model->get_menu_from($parent['page_id'], 10, true);
		$data['url'] = $this->url;
		$out['text'] = $this->load->view('modules/articles/index', $data, true);
		return $out;
	}
	public function show($args) {
		$data['url'] = $this->url;
		$id = $args[0];
		$data['page'] = $page = $this->db->select()->from('content')->where('page_id', $id)->get()->row_array();
		if (sizeof($page) <= 0 || $page['page_status'] == 0) redirect('/');
		$parent = $this->db->select()->from('content')->where('page_model', 'articles')->where('page_function', 'index')->get()->row_array();
		$out['data']['crumps'] = $this->content_model->getCrumps($page['page_path'], $this->url, $parent['page_id']);
		$out['data']['title'] = $page['page_title'];
		$out['text'] = $this->load->view('modules/articles/show', $data, true);
		return $out;
	}
	function map() {


		$map = directory_map('./application/cache/db/map+index/', 1);
		$stat=stat("./application/cache/db/map+index/".$map[0]);
		if (time() - $stat[9] > 259200)  {
			$this->db->cache_delete_all();
		}
		$data['pages'] = $this->content_model->get_menu_from(0, 10, true, false);
		$data['url'] = $this->url;
		$data['catalog'] = $this->catalog_service_model->get_catalog_from(0, 10, true);
		$data['news'] = $this->news_model->get_all_list();
		$out['text'] = $this->load->view('modules/articles/map', $data, true);

		return $out;
	}
}